﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
namespace Tong.DataOperation
{
    /// <summary>
    /// CX_Column数据库操作类。
    /// </summary>
    public class Data_CX_Column
    {
        private decimal cX_Column_id = 0;
        /// <summary>
        /// 栏目RegUser_id
        /// </summary>
        public decimal CX_Column_id
        {
            get { return cX_Column_id; }
            set { cX_Column_id = value; }
        }
        public static string _CX_Column_id = "CX_Column_id";
        private decimal cX_Column_followid = 0;
        /// <summary>
        /// 栏目从属id
        /// </summary>
        public decimal CX_Column_followid
        {
            get { return cX_Column_followid; }
            set { cX_Column_followid = value; }
        }
        public static string _CX_Column_followid = "CX_Column_followid";
        private string cX_Column_Name = "";
        /// <summary>
        /// 栏目名
        /// </summary>
        public string CX_Column_Name
        {
            get { return cX_Column_Name; }
            set { cX_Column_Name = value; }
        }
        public static string _CX_Column_Name = "CX_Column_Name";
        private int cX_Column_Class = 0;
        /// <summary>
        /// 栏目分类
        /// </summary>
        public int CX_Column_Class
        {
            get { return cX_Column_Class; }
            set { cX_Column_Class = value; }
        }
        public static string _CX_Column_Class = "CX_Column_Class";
        private string cX_Column_Directory = "";
        /// <summary>
        /// 栏目目录
        /// </summary>
        public string CX_Column_Directory
        {
            get { return cX_Column_Directory; }
            set { cX_Column_Directory = value; }
        }
        public static string _CX_Column_Directory = "CX_Column_Directory";
        private string cX_Column_Explair = "";
        /// <summary>
        /// 栏目说明
        /// </summary>
        public string CX_Column_Explair
        {
            get { return cX_Column_Explair; }
            set { cX_Column_Explair = value; }
        }
        public static string _CX_Column_Explair = "CX_Column_Explair";
        private string cX_Column_ItemTemplate_Url = "";
        /// <summary>
        /// 栏目模板地址
        /// </summary>
        public string CX_Column_ItemTemplate_Url
        {
            get { return cX_Column_ItemTemplate_Url; }
            set { cX_Column_ItemTemplate_Url = value; }
        }
        public static string _CX_Column_ItemTemplate_Url = "CX_Column_ItemTemplate_Url";
        private string cX_Column_ItemTeplate_Parame = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_Column_ItemTeplate_Parame
        {
            get { return cX_Column_ItemTeplate_Parame; }
            set { cX_Column_ItemTeplate_Parame = value; }
        }
        public static string _CX_Column_ItemTeplate_Parame = "CX_Column_ItemTeplate_Parame";
        private int cX_Column_Sort = 0;
        /// <summary>
        /// 栏目排序
        /// </summary>
        public int CX_Column_Sort
        {
            get { return cX_Column_Sort; }
            set { cX_Column_Sort = value; }
        }
        public static string _CX_Column_Sort = "CX_Column_Sort";
        private string cX_CX_Column_Tab_Name = "";
        /// <summary>
        /// 栏目英文名 用于指定数据库表名
        /// </summary>
        public string CX_CX_Column_Tab_Name
        {
            get { return cX_CX_Column_Tab_Name; }
            set { cX_CX_Column_Tab_Name = value; }
        }
        public static string _CX_CX_Column_Tab_Name = "CX_CX_Column_Tab_Name";
        private int cX_Column_LX = 0;
        /// <summary>
        /// 数字类型  栏目类型 0 为一般栏目 显示分类 1 为新闻栏目用于新闻分类时使用 0 将不进行新闻生成
        /// </summary>
        public int CX_Column_LX
        {
            get { return cX_Column_LX; }
            set { cX_Column_LX = value; }
        }
        public static string _CX_Column_LX = "CX_Column_LX";
        private string cX_Column_Pic = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_Column_Pic
        {
            get { return cX_Column_Pic; }
            set { cX_Column_Pic = value; }
        }
        public static string _CX_Column_Pic = "CX_Column_Pic";
    }

    #region 定义类型 定义类型  CX_Column  的操作方法
    /// <summary>
    /// 用于对相应表 CX_Column 进行操作的类弄
    /// </summary>
    /// <typeparam name="T">表类型对象</typeparam>
    [System.ComponentModel.DataObject]
    public class Data_CX_Column_QueryTable<T> : DataIQueryTable<Data_CX_Column> where T : Data_CX_Column, new()
    {
        /// <summary>
        /// 实例化对象
        /// </summary>
        private T DataClass = new T();

        /// <summary>
        /// 数据操作常用方法
        /// </summary>
        private Tong.TongUse TextData = new TongUse();

        private string orderBy;
        /// <summary>
        /// 要初始化排序条件
        /// </summary>
        public string OrderBy
        {
            get
            {
                return orderBy;
            }
            set
            {
                orderBy = value;
            }
        }

        private string errorInfo = "";
        /// <summary>
        /// 出错的信息
        /// </summary>
        public string ErrorInfo
        {
            get
            {
                return errorInfo;
            }
            set
            {
                errorInfo = value;
            }
        }

        /// <summary>
        /// 用于实现插入的方法
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_inser(Data_CX_Column t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = "INSERT INTO [CX_Column] (" +
               "			CX_Column_followid" +
               "			,CX_Column_Name" +
               "			,CX_Column_Class" +
               "			,CX_Column_Directory" +
               "			,CX_Column_Explair" +
               "			,CX_Column_ItemTemplate_Url" +
               "			,CX_Column_ItemTeplate_Parame" +
               "			,CX_Column_Sort" +
               "			,CX_CX_Column_Tab_Name" +
               "			,CX_Column_LX" +
               "			,CX_Column_Pic" +
               "			)" +
               "values(" +
               "			@CX_Column_followid" +
               "			,@CX_Column_Name" +
               "			,@CX_Column_Class" +
               "			,@CX_Column_Directory" +
               "			,@CX_Column_Explair" +
               "			,@CX_Column_ItemTemplate_Url" +
               "			,@CX_Column_ItemTeplate_Parame" +
               "			,@CX_Column_Sort" +
               "			,@CX_CX_Column_Tab_Name" +
               "			,@CX_Column_LX" +
               "			,@CX_Column_Pic" +
               "			)";

                Cmd.Parameters.Add(new SqlParameter("@CX_Column_followid", t.CX_Column_followid));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Name", t.CX_Column_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Class", t.CX_Column_Class));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Directory", t.CX_Column_Directory));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Explair", t.CX_Column_Explair));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_ItemTemplate_Url", t.CX_Column_ItemTemplate_Url));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_ItemTeplate_Parame", t.CX_Column_ItemTeplate_Parame));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Sort", t.CX_Column_Sort));
                Cmd.Parameters.Add(new SqlParameter("@CX_CX_Column_Tab_Name", t.CX_CX_Column_Tab_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_LX", t.CX_Column_LX));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Pic", t.CX_Column_Pic));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_Column表的添加操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_update(Data_CX_Column t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = " UPDATE [CX_Column] Set " +
               "			CX_Column_followid=@CX_Column_followid" +
               "			,CX_Column_Name=@CX_Column_Name" +
               "			,CX_Column_Class=@CX_Column_Class" +
               "			,CX_Column_Directory=@CX_Column_Directory" +
               "			,CX_Column_Explair=@CX_Column_Explair" +
               "			,CX_Column_ItemTemplate_Url=@CX_Column_ItemTemplate_Url" +
               "			,CX_Column_ItemTeplate_Parame=@CX_Column_ItemTeplate_Parame" +
               "			,CX_Column_Sort=@CX_Column_Sort" +
               "			,CX_CX_Column_Tab_Name=@CX_CX_Column_Tab_Name" +
               "			,CX_Column_LX=@CX_Column_LX" +
               "			,CX_Column_Pic=@CX_Column_Pic" +
               "			" +
               "			where [CX_Column_id] = @CX_Column_id" +
               "			";

                Cmd.Parameters.Add(new SqlParameter("@CX_Column_followid", t.CX_Column_followid));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Name", t.CX_Column_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Class", t.CX_Column_Class));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Directory", t.CX_Column_Directory));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Explair", t.CX_Column_Explair));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_ItemTemplate_Url", t.CX_Column_ItemTemplate_Url));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_ItemTeplate_Parame", t.CX_Column_ItemTeplate_Parame));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Sort", t.CX_Column_Sort));
                Cmd.Parameters.Add(new SqlParameter("@CX_CX_Column_Tab_Name", t.CX_CX_Column_Tab_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_LX", t.CX_Column_LX));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_Pic", t.CX_Column_Pic));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_id", t.CX_Column_id));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_Column表的更新操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 传入 实例化的对象的主键值 此对象一定要指定主键
        /// </summary>
        /// <param name="t">实例化的数据库表对象</param>
        /// <returns></returns>
        public DataSet Operate_Select(Data_CX_Column DataTable_Obj)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;
            #region CX_Column 的查询方法

            MyDa.SelectCommand.CommandText = "select * from  [CX_Column] where  [CX_Column_id] = @CX_Column_id  " + OrderBy;
            MyDa.SelectCommand.Parameters.Add("@CX_Column_id", DataTable_Obj.CX_Column_id);
            #endregion

            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;


        }
        /// <summary>
        /// 传入一个 ID 值 用于得这个ID 值下的所有 数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            MyDa.SelectCommand.CommandText = "select * from [CX_Column] where  [CX_Column_id] =" + ID + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        /// <summary>
        ///  传入字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID, string CoulmnName)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            MyDa.SelectCommand.CommandText = "select " + CoulmnName + " from [CX_Column] where  [CX_Column_id] =" + ID + "  " + OrderBy;
            #endregion


            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 字段名 返回一个字段的值 调用条数
        /// </summary>
        /// <param name="ID">字段名</param>
        /// <param name="CoulmnName">调用条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_Column]     " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 传入字段集合 返回条数据
        /// </summary>
        /// <param name="CoulmnName">字段的数组  数组长度为0 为 得到全部的字段  </param>
        /// <param name="RecordNum">得到记录的条数</param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum)
        {
            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法

            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }

            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_Column]    " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        ///  传入多个字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_Column]   where " + Where + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

        /// <summary>
        ///  传入字段集合 返回条数据
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到 字段的数组  数组长度为0 为 得到全部的字段</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }
            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_Column]   where " + Where + "   " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        #region 数据转对象

        /// <summary>
        ///  传入读出数据的条数 条件
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public Data_CX_Column[] Oper_SelectToObject(int RecordNum, string Where)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum, Where));
        }

        /// <summary>
        ///  传入读出数据的条数 
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public Data_CX_Column[] Oper_SelectToObject(int RecordNum)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum));
        }

        #endregion

        #region  用于实现数据转换成类型的方法

        /// <summary>
        /// 把对应表的数据转成对象
        /// </summary>
        /// <param name="MyDs">传入的dataset</param>
        /// <returns></returns>
        private Data_CX_Column[] ConvertToObject(DataSet MyDs)
        {

            DataTable Mydt = MyDs.Tables[0];
            //当前的记录数，默认 为 0
            int Count = 0;
            //定义一个方法用于显示数据 类型的集合
            Data_CX_Column[] p = new Data_CX_Column[1];
            if (Mydt.Rows.Count == 0)
            {
                p = new Data_CX_Column[1];
                Count = 1;
            }
            else
            {
                p = new Data_CX_Column[Mydt.Rows.Count];
            }

            try
            {
                for (int i = 0; i < Mydt.Rows.Count; i++)
                {
                    Data_CX_Column Mydato = new Data_CX_Column();
                    #region 实现转换的方法
                    Mydato.CX_Column_id = (decimal)(Mydt.Rows[i][Data_CX_Column._CX_Column_id].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_Column._CX_Column_id]);
                    Mydato.CX_Column_followid = (decimal)(Mydt.Rows[i][Data_CX_Column._CX_Column_followid].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_Column._CX_Column_followid]);
                    Mydato.CX_Column_Name = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_Name].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_Name]);
                    Mydato.CX_Column_Class = (int)(Mydt.Rows[i][Data_CX_Column._CX_Column_Class].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_Column._CX_Column_Class]);
                    Mydato.CX_Column_Directory = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_Directory].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_Directory]);
                    Mydato.CX_Column_Explair = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_Explair].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_Explair]);
                    Mydato.CX_Column_ItemTemplate_Url = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_ItemTemplate_Url].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_ItemTemplate_Url]);
                    Mydato.CX_Column_ItemTeplate_Parame = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_ItemTeplate_Parame].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_ItemTeplate_Parame]);
                    Mydato.CX_Column_Sort = (int)(Mydt.Rows[i][Data_CX_Column._CX_Column_Sort].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_Column._CX_Column_Sort]);
                    Mydato.CX_CX_Column_Tab_Name = (string)(Mydt.Rows[i][Data_CX_Column._CX_CX_Column_Tab_Name].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_CX_Column_Tab_Name]);
                    Mydato.CX_Column_LX = (int)(Mydt.Rows[i][Data_CX_Column._CX_Column_LX].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_Column._CX_Column_LX]);
                    Mydato.CX_Column_Pic = (string)(Mydt.Rows[i][Data_CX_Column._CX_Column_Pic].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_Column._CX_Column_Pic]);

                    #endregion
                    p[i] = Mydato;
                }
            }
            catch (Exception ex)
            {
                errorInfo += "执行  把对应表的数据转成对象时出现错误" + ex.Message + ex.Source;
            }
            if (Count != 0)
            {
                p[0] = new Data_CX_Column();

            }

            return p;


        }
        #endregion


        /// <summary>
        /// 执行SQL语句 返回dataSet
        /// </summary>
        /// <typeparam name="Tab">数据表</typeparam>
        /// <param name="Sql">执行的SQL</param>
        /// <returns></returns>
        public DataSet ExecuteQuery(string Sql)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_Column 的查询方法
            MyDa.SelectCommand.CommandText = Sql;
            #endregion



            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

    }

    #endregion


    /// <summary>
    /// CX_NEWS数据库操作类。
    /// </summary>
    public class Data_CX_NEWS
    {
        private decimal cX_NEWS_id = 0;
        /// <summary>
        /// 
        /// </summary>
        public decimal CX_NEWS_id
        {
            get { return cX_NEWS_id; }
            set { cX_NEWS_id = value; }
        }
        public static string _CX_NEWS_id = "CX_NEWS_id";
        private string cX_NEWS_Name = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Name
        {
            get { return cX_NEWS_Name; }
            set { cX_NEWS_Name = value; }
        }
        public static string _CX_NEWS_Name = "CX_NEWS_Name";
        private decimal cX_NEWS_Class_id = 0;
        /// <summary>
        /// 新闻栏目
        /// </summary>
        public decimal CX_NEWS_Class_id
        {
            get { return cX_NEWS_Class_id; }
            set { cX_NEWS_Class_id = value; }
        }
        public static string _CX_NEWS_Class_id = "CX_NEWS_Class_id";
        private string cX_NEWS_Creater = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Creater
        {
            get { return cX_NEWS_Creater; }
            set { cX_NEWS_Creater = value; }
        }
        public static string _CX_NEWS_Creater = "CX_NEWS_Creater";
        private string cX_NEWS_From = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_From
        {
            get { return cX_NEWS_From; }
            set { cX_NEWS_From = value; }
        }
        public static string _CX_NEWS_From = "CX_NEWS_From";
        private string cX_NEWS_Top = "";
        /// <summary>
        /// 头条新闻
        /// </summary>
        public string CX_NEWS_Top
        {
            get { return cX_NEWS_Top; }
            set { cX_NEWS_Top = value; }
        }
        public static string _CX_NEWS_Top = "CX_NEWS_Top";
        private string cX_NEWS_Pic = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Pic
        {
            get { return cX_NEWS_Pic; }
            set { cX_NEWS_Pic = value; }
        }
        public static string _CX_NEWS_Pic = "CX_NEWS_Pic";
        private string cX_NEWS_Pic_Url = "";
        /// <summary>
        /// 图片url
        /// </summary>
        public string CX_NEWS_Pic_Url
        {
            get { return cX_NEWS_Pic_Url; }
            set { cX_NEWS_Pic_Url = value; }
        }
        public static string _CX_NEWS_Pic_Url = "CX_NEWS_Pic_Url";
        private DateTime cX_NEWS_PublicTime = DateTime.Now;
        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTime CX_NEWS_PublicTime
        {
            get { return cX_NEWS_PublicTime; }
            set { cX_NEWS_PublicTime = value; }
        }
        public static string _CX_NEWS_PublicTime = "CX_NEWS_PublicTime";
        private string cX_NEWS_Cont = "";
        /// <summary>
        /// 新闻内容
        /// </summary>
        public string CX_NEWS_Cont
        {
            get { return cX_NEWS_Cont; }
            set { cX_NEWS_Cont = value; }
        }
        public static string _CX_NEWS_Cont = "CX_NEWS_Cont";
        private decimal cX_NEWS_Sort = 0;
        /// <summary>
        /// 
        /// </summary>
        public decimal CX_NEWS_Sort
        {
            get { return cX_NEWS_Sort; }
            set { cX_NEWS_Sort = value; }
        }
        public static string _CX_NEWS_Sort = "CX_NEWS_Sort";
        private string cx_keyWord_Name = "";
        /// <summary>
        /// keyword
        /// </summary>
        public string Cx_keyWord_Name
        {
            get { return cx_keyWord_Name; }
            set { cx_keyWord_Name = value; }
        }
        public static string _Cx_keyWord_Name = "Cx_keyWord_Name";
        private string cX_NEWS_Title = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Title
        {
            get { return cX_NEWS_Title; }
            set { cX_NEWS_Title = value; }
        }
        public static string _CX_NEWS_Title = "CX_NEWS_Title";
        private string cX_NEWS_KeyWords = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_KeyWords
        {
            get { return cX_NEWS_KeyWords; }
            set { cX_NEWS_KeyWords = value; }
        }
        public static string _CX_NEWS_KeyWords = "CX_NEWS_KeyWords";
        private string cX_NEWS_Description = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Description
        {
            get { return cX_NEWS_Description; }
            set { cX_NEWS_Description = value; }
        }
        public static string _CX_NEWS_Description = "CX_NEWS_Description";
        private string cX_NEWS_Class_Edit = "";
        /// <summary>
        /// 
        /// </summary>
        public string CX_NEWS_Class_Edit
        {
            get { return cX_NEWS_Class_Edit; }
            set { cX_NEWS_Class_Edit = value; }
        }
        public static string _CX_NEWS_Class_Edit = "CX_NEWS_Class_Edit";
    }

    #region 定义类型 定义类型  CX_NEWS  的操作方法
    /// <summary>
    /// 用于对相应表 CX_NEWS 进行操作的类弄
    /// </summary>
    /// <typeparam name="T">表类型对象</typeparam>
    [System.ComponentModel.DataObject]
    public class Data_CX_NEWS_QueryTable<T> : DataIQueryTable<Data_CX_NEWS> where T : Data_CX_NEWS, new()
    {
        /// <summary>
        /// 实例化对象
        /// </summary>
        private T DataClass = new T();

        /// <summary>
        /// 数据操作常用方法
        /// </summary>
        private Tong.TongUse TextData = new TongUse();

        private string orderBy;
        /// <summary>
        /// 要初始化排序条件
        /// </summary>
        public string OrderBy
        {
            get
            {
                return orderBy;
            }
            set
            {
                orderBy = value;
            }
        }

        private string errorInfo = "";
        /// <summary>
        /// 出错的信息
        /// </summary>
        public string ErrorInfo
        {
            get
            {
                return errorInfo;
            }
            set
            {
                errorInfo = value;
            }
        }

        /// <summary>
        /// 用于实现插入的方法
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_inser(Data_CX_NEWS t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = "INSERT INTO [CX_NEWS] (" +
               "			CX_NEWS_Name" +
               "			,CX_NEWS_Class_id" +
               "			,CX_NEWS_Creater" +
               "			,CX_NEWS_From" +
               "			,CX_NEWS_Top" +
               "			,CX_NEWS_Pic" +
               "			,CX_NEWS_Pic_Url" +
               "			,CX_NEWS_PublicTime" +
               "			,CX_NEWS_Cont" +
               "			,CX_NEWS_Sort" +
               "			,Cx_keyWord_Name" +
               "			,CX_NEWS_Title" +
               "			,CX_NEWS_KeyWords" +
               "			,CX_NEWS_Description" +
               "			,CX_NEWS_Class_Edit" +
               "			)" +
               "values(" +
               "			@CX_NEWS_Name" +
               "			,@CX_NEWS_Class_id" +
               "			,@CX_NEWS_Creater" +
               "			,@CX_NEWS_From" +
               "			,@CX_NEWS_Top" +
               "			,@CX_NEWS_Pic" +
               "			,@CX_NEWS_Pic_Url" +
               "			,@CX_NEWS_PublicTime" +
               "			,@CX_NEWS_Cont" +
               "			,@CX_NEWS_Sort" +
               "			,@Cx_keyWord_Name" +
               "			,@CX_NEWS_Title" +
               "			,@CX_NEWS_KeyWords" +
               "			,@CX_NEWS_Description" +
               "			,@CX_NEWS_Class_Edit" +
               "			)";

                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Name", t.CX_NEWS_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_id", t.CX_NEWS_Class_id));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Creater", t.CX_NEWS_Creater));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_From", t.CX_NEWS_From));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Top", t.CX_NEWS_Top));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Pic", t.CX_NEWS_Pic));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Pic_Url", t.CX_NEWS_Pic_Url));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_PublicTime", t.CX_NEWS_PublicTime));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Cont", t.CX_NEWS_Cont));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Sort", t.CX_NEWS_Sort));
                Cmd.Parameters.Add(new SqlParameter("@Cx_keyWord_Name", t.Cx_keyWord_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Title", t.CX_NEWS_Title));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_KeyWords", t.CX_NEWS_KeyWords));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Description", t.CX_NEWS_Description));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Edit", t.CX_NEWS_Class_Edit));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_NEWS表的添加操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_update(Data_CX_NEWS t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = " UPDATE [CX_NEWS] Set " +
               "			CX_NEWS_Name=@CX_NEWS_Name" +
               "			,CX_NEWS_Class_id=@CX_NEWS_Class_id" +
               "			,CX_NEWS_Creater=@CX_NEWS_Creater" +
               "			,CX_NEWS_From=@CX_NEWS_From" +
               "			,CX_NEWS_Top=@CX_NEWS_Top" +
               "			,CX_NEWS_Pic=@CX_NEWS_Pic" +
               "			,CX_NEWS_Pic_Url=@CX_NEWS_Pic_Url" +
               "			,CX_NEWS_PublicTime=@CX_NEWS_PublicTime" +
               "			,CX_NEWS_Cont=@CX_NEWS_Cont" +
               "			,CX_NEWS_Sort=@CX_NEWS_Sort" +
               "			,Cx_keyWord_Name=@Cx_keyWord_Name" +
               "			,CX_NEWS_Title=@CX_NEWS_Title" +
               "			,CX_NEWS_KeyWords=@CX_NEWS_KeyWords" +
               "			,CX_NEWS_Description=@CX_NEWS_Description" +
               "			,CX_NEWS_Class_Edit=@CX_NEWS_Class_Edit" +
               "			" +
               "			where [CX_NEWS_id] = @CX_NEWS_id" +
               "			";

                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Name", t.CX_NEWS_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_id", t.CX_NEWS_Class_id));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Creater", t.CX_NEWS_Creater));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_From", t.CX_NEWS_From));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Top", t.CX_NEWS_Top));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Pic", t.CX_NEWS_Pic));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Pic_Url", t.CX_NEWS_Pic_Url));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_PublicTime", t.CX_NEWS_PublicTime));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Cont", t.CX_NEWS_Cont));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Sort", t.CX_NEWS_Sort));
                Cmd.Parameters.Add(new SqlParameter("@Cx_keyWord_Name", t.Cx_keyWord_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Title", t.CX_NEWS_Title));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_KeyWords", t.CX_NEWS_KeyWords));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Description", t.CX_NEWS_Description));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Edit", t.CX_NEWS_Class_Edit));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_id", t.CX_NEWS_id));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_NEWS表的更新操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 传入 实例化的对象的主键值 此对象一定要指定主键
        /// </summary>
        /// <param name="t">实例化的数据库表对象</param>
        /// <returns></returns>
        public DataSet Operate_Select(Data_CX_NEWS DataTable_Obj)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;
            #region CX_NEWS 的查询方法

            MyDa.SelectCommand.CommandText = "select * from  [CX_NEWS] where  [CX_NEWS_id] = @CX_NEWS_id  " + OrderBy;
            MyDa.SelectCommand.Parameters.Add("@CX_NEWS_id", DataTable_Obj.CX_NEWS_id);
            #endregion

            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;


        }
        /// <summary>
        /// 传入一个 ID 值 用于得这个ID 值下的所有 数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            MyDa.SelectCommand.CommandText = "select * from [CX_NEWS] where  [CX_NEWS_id] =" + ID + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        /// <summary>
        ///  传入字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID, string CoulmnName)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            MyDa.SelectCommand.CommandText = "select " + CoulmnName + " from [CX_NEWS] where  [CX_NEWS_id] =" + ID + "  " + OrderBy;
            #endregion


            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 字段名 返回一个字段的值 调用条数
        /// </summary>
        /// <param name="ID">字段名</param>
        /// <param name="CoulmnName">调用条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_NEWS]     " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 传入字段集合 返回条数据
        /// </summary>
        /// <param name="CoulmnName">字段的数组  数组长度为0 为 得到全部的字段  </param>
        /// <param name="RecordNum">得到记录的条数</param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum)
        {
            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法

            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }

            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_NEWS]    " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        ///  传入多个字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_NEWS]   where " + Where + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

        /// <summary>
        ///  传入字段集合 返回条数据
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到 字段的数组  数组长度为0 为 得到全部的字段</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }
            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_NEWS]   where " + Where + "   " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        #region 数据转对象

        /// <summary>
        ///  传入读出数据的条数 条件
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public Data_CX_NEWS[] Oper_SelectToObject(int RecordNum, string Where)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum, Where));
        }

        /// <summary>
        ///  传入读出数据的条数 
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public Data_CX_NEWS[] Oper_SelectToObject(int RecordNum)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum));
        }

        #endregion

        #region  用于实现数据转换成类型的方法

        /// <summary>
        /// 把对应表的数据转成对象
        /// </summary>
        /// <param name="MyDs">传入的dataset</param>
        /// <returns></returns>
        private Data_CX_NEWS[] ConvertToObject(DataSet MyDs)
        {

            DataTable Mydt = MyDs.Tables[0];
            //当前的记录数，默认 为 0
            int Count = 0;
            //定义一个方法用于显示数据 类型的集合
            Data_CX_NEWS[] p = new Data_CX_NEWS[1];
            if (Mydt.Rows.Count == 0)
            {
                p = new Data_CX_NEWS[1];
                Count = 1;
            }
            else
            {
                p = new Data_CX_NEWS[Mydt.Rows.Count];
            }

            try
            {
                for (int i = 0; i < Mydt.Rows.Count; i++)
                {
                    Data_CX_NEWS Mydato = new Data_CX_NEWS();
                    #region 实现转换的方法
                    Mydato.CX_NEWS_id = (decimal)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_id].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_id]);
                    Mydato.CX_NEWS_Name = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Name].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Name]);
                    Mydato.CX_NEWS_Class_id = (decimal)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Class_id].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Class_id]);
                    Mydato.CX_NEWS_Creater = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Creater].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Creater]);
                    Mydato.CX_NEWS_From = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_From].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_From]);
                    Mydato.CX_NEWS_Top = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Top].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Top]);
                    Mydato.CX_NEWS_Pic = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Pic].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Pic]);
                    Mydato.CX_NEWS_Pic_Url = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Pic_Url].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Pic_Url]);
                    Mydato.CX_NEWS_PublicTime = (DateTime)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_PublicTime].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? DateTime.Now : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_PublicTime]);
                    Mydato.CX_NEWS_Cont = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Cont].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Cont]);
                    Mydato.CX_NEWS_Sort = (decimal)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Sort].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Sort]);
                    Mydato.Cx_keyWord_Name = (string)(Mydt.Rows[i][Data_CX_NEWS._Cx_keyWord_Name].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._Cx_keyWord_Name]);
                    Mydato.CX_NEWS_Title = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Title].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Title]);
                    Mydato.CX_NEWS_KeyWords = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_KeyWords].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_KeyWords]);
                    Mydato.CX_NEWS_Description = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Description].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Description]);
                    Mydato.CX_NEWS_Class_Edit = (string)(Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Class_Edit].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS._CX_NEWS_Class_Edit]);

                    #endregion
                    p[i] = Mydato;
                }
            }
            catch (Exception ex)
            {
                errorInfo += "执行  把对应表的数据转成对象时出现错误" + ex.Message + ex.Source;
            }
            if (Count != 0)
            {
                p[0] = new Data_CX_NEWS();

            }

            return p;


        }
        #endregion


        /// <summary>
        /// 执行SQL语句 返回dataSet
        /// </summary>
        /// <typeparam name="Tab">数据表</typeparam>
        /// <param name="Sql">执行的SQL</param>
        /// <returns></returns>
        public DataSet ExecuteQuery(string Sql)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS 的查询方法
            MyDa.SelectCommand.CommandText = Sql;
            #endregion



            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

    }

    #endregion

    /// <summary>
    /// CX_NEWS_Class数据库操作类。
    /// </summary>
    public class Data_CX_NEWS_Class
    {
        private decimal cX_NEWS_Class_id = 0;
        /// <summary>
        /// 新闻设定 id
        /// </summary>
        public decimal CX_NEWS_Class_id
        {
            get { return cX_NEWS_Class_id; }
            set { cX_NEWS_Class_id = value; }
        }
        public static string _CX_NEWS_Class_id = "CX_NEWS_Class_id";
        private string cX_NEWS_Class_Name = "";
        /// <summary>
        /// 新闻设定名
        /// </summary>
        public string CX_NEWS_Class_Name
        {
            get { return cX_NEWS_Class_Name; }
            set { cX_NEWS_Class_Name = value; }
        }
        public static string _CX_NEWS_Class_Name = "CX_NEWS_Class_Name";
        private decimal cX_Column_id = 0;
        /// <summary>
        /// 新闻设定所属栏目
        /// </summary>
        public decimal CX_Column_id
        {
            get { return cX_Column_id; }
            set { cX_Column_id = value; }
        }
        public static string _CX_Column_id = "CX_Column_id";
        private string cX_NEWS_Class_Explier = "";
        /// <summary>
        /// 新闻设定说明
        /// </summary>
        public string CX_NEWS_Class_Explier
        {
            get { return cX_NEWS_Class_Explier; }
            set { cX_NEWS_Class_Explier = value; }
        }
        public static string _CX_NEWS_Class_Explier = "CX_NEWS_Class_Explier";
        private string cX_NEWS_Class_Itemplitate_Address = "";
        /// <summary>
        /// 模板地址
        /// </summary>
        public string CX_NEWS_Class_Itemplitate_Address
        {
            get { return cX_NEWS_Class_Itemplitate_Address; }
            set { cX_NEWS_Class_Itemplitate_Address = value; }
        }
        public static string _CX_NEWS_Class_Itemplitate_Address = "CX_NEWS_Class_Itemplitate_Address";
        private string cX_NEWS_Class_Itemplitate_Parame = "";
        /// <summary>
        /// 新闻模板参数
        /// </summary>
        public string CX_NEWS_Class_Itemplitate_Parame
        {
            get { return cX_NEWS_Class_Itemplitate_Parame; }
            set { cX_NEWS_Class_Itemplitate_Parame = value; }
        }
        public static string _CX_NEWS_Class_Itemplitate_Parame = "CX_NEWS_Class_Itemplitate_Parame";
        private string cX_NEWS_Class_Pic = "";
        /// <summary>
        /// 显示图片
        /// </summary>
        public string CX_NEWS_Class_Pic
        {
            get { return cX_NEWS_Class_Pic; }
            set { cX_NEWS_Class_Pic = value; }
        }
        public static string _CX_NEWS_Class_Pic = "CX_NEWS_Class_Pic";
        private string cX_NEWS_Class_CreateFielfront = "";
        /// <summary>
        /// 生成文件名前缀
        /// </summary>
        public string CX_NEWS_Class_CreateFielfront
        {
            get { return cX_NEWS_Class_CreateFielfront; }
            set { cX_NEWS_Class_CreateFielfront = value; }
        }
        public static string _CX_NEWS_Class_CreateFielfront = "CX_NEWS_Class_CreateFielfront";
        private string cX_NEWS_Class_Directory = "";
        /// <summary>
        /// 生成目录
        /// </summary>
        public string CX_NEWS_Class_Directory
        {
            get { return cX_NEWS_Class_Directory; }
            set { cX_NEWS_Class_Directory = value; }
        }
        public static string _CX_NEWS_Class_Directory = "CX_NEWS_Class_Directory";
    }

    #region 定义类型 定义类型  CX_NEWS_Class  的操作方法
    /// <summary>
    /// 用于对相应表 CX_NEWS_Class 进行操作的类弄
    /// </summary>
    /// <typeparam name="T">表类型对象</typeparam>
    [System.ComponentModel.DataObject]
    public class Data_CX_NEWS_Class_QueryTable<T> : DataIQueryTable<Data_CX_NEWS_Class> where T : Data_CX_NEWS_Class, new()
    {
        /// <summary>
        /// 实例化对象
        /// </summary>
        private T DataClass = new T();

        /// <summary>
        /// 数据操作常用方法
        /// </summary>
        private Tong.TongUse TextData = new TongUse();

        private string orderBy;
        /// <summary>
        /// 要初始化排序条件
        /// </summary>
        public string OrderBy
        {
            get
            {
                return orderBy;
            }
            set
            {
                orderBy = value;
            }
        }

        private string errorInfo = "";
        /// <summary>
        /// 出错的信息
        /// </summary>
        public string ErrorInfo
        {
            get
            {
                return errorInfo;
            }
            set
            {
                errorInfo = value;
            }
        }

        /// <summary>
        /// 用于实现插入的方法
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_inser(Data_CX_NEWS_Class t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = "INSERT INTO [CX_NEWS_Class] (" +
               "			CX_NEWS_Class_Name" +
               "			,CX_Column_id" +
               "			,CX_NEWS_Class_Explier" +
               "			,CX_NEWS_Class_Itemplitate_Address" +
               "			,CX_NEWS_Class_Itemplitate_Parame" +
               "			,CX_NEWS_Class_Pic" +
               "			,CX_NEWS_Class_CreateFielfront" +
               "			,CX_NEWS_Class_Directory" +
               "			)" +
               "values(" +
               "			@CX_NEWS_Class_Name" +
               "			,@CX_Column_id" +
               "			,@CX_NEWS_Class_Explier" +
               "			,@CX_NEWS_Class_Itemplitate_Address" +
               "			,@CX_NEWS_Class_Itemplitate_Parame" +
               "			,@CX_NEWS_Class_Pic" +
               "			,@CX_NEWS_Class_CreateFielfront" +
               "			,@CX_NEWS_Class_Directory" +
               "			)";

                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Name", t.CX_NEWS_Class_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_id", t.CX_Column_id));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Explier", t.CX_NEWS_Class_Explier));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Itemplitate_Address", t.CX_NEWS_Class_Itemplitate_Address));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Itemplitate_Parame", t.CX_NEWS_Class_Itemplitate_Parame));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Pic", t.CX_NEWS_Class_Pic));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_CreateFielfront", t.CX_NEWS_Class_CreateFielfront));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Directory", t.CX_NEWS_Class_Directory));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_NEWS_Class表的添加操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="t">更新的对象</param>
        /// <returns></returns>
        public bool Operate_update(Data_CX_NEWS_Class t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }

            try
            {
                SqlCommand Cmd = new SqlCommand();
                Cmd.CommandType = CommandType.Text;
                Cmd.Connection = MySql;
                Cmd.CommandText = " UPDATE [CX_NEWS_Class] Set " +
               "			CX_NEWS_Class_Name=@CX_NEWS_Class_Name" +
               "			,CX_Column_id=@CX_Column_id" +
               "			,CX_NEWS_Class_Explier=@CX_NEWS_Class_Explier" +
               "			,CX_NEWS_Class_Itemplitate_Address=@CX_NEWS_Class_Itemplitate_Address" +
               "			,CX_NEWS_Class_Itemplitate_Parame=@CX_NEWS_Class_Itemplitate_Parame" +
               "			,CX_NEWS_Class_Pic=@CX_NEWS_Class_Pic" +
               "			,CX_NEWS_Class_CreateFielfront=@CX_NEWS_Class_CreateFielfront" +
               "			,CX_NEWS_Class_Directory=@CX_NEWS_Class_Directory" +
               "			" +
               "			where [CX_NEWS_Class_id] = @CX_NEWS_Class_id" +
               "			";

                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Name", t.CX_NEWS_Class_Name));
                Cmd.Parameters.Add(new SqlParameter("@CX_Column_id", t.CX_Column_id));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Explier", t.CX_NEWS_Class_Explier));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Itemplitate_Address", t.CX_NEWS_Class_Itemplitate_Address));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Itemplitate_Parame", t.CX_NEWS_Class_Itemplitate_Parame));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Pic", t.CX_NEWS_Class_Pic));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_CreateFielfront", t.CX_NEWS_Class_CreateFielfront));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_Directory", t.CX_NEWS_Class_Directory));
                Cmd.Parameters.Add(new SqlParameter("@CX_NEWS_Class_id", t.CX_NEWS_Class_id));
                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ErrorInfo += "执行 CX_NEWS_Class表的更新操作时出现错误" + ex.Message;
                return false;
            }
            return true;
            MySql.Close();
        }

        /// <summary>
        /// 传入 实例化的对象的主键值 此对象一定要指定主键
        /// </summary>
        /// <param name="t">实例化的数据库表对象</param>
        /// <returns></returns>
        public DataSet Operate_Select(Data_CX_NEWS_Class DataTable_Obj)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;
            #region CX_NEWS_Class 的查询方法

            MyDa.SelectCommand.CommandText = "select * from  [CX_NEWS_Class] where  [CX_NEWS_Class_id] = @CX_NEWS_Class_id  " + OrderBy;
            MyDa.SelectCommand.Parameters.Add("@CX_NEWS_Class_id", DataTable_Obj.CX_NEWS_Class_id);
            #endregion

            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;


        }
        /// <summary>
        /// 传入一个 ID 值 用于得这个ID 值下的所有 数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            MyDa.SelectCommand.CommandText = "select * from [CX_NEWS_Class] where  [CX_NEWS_Class_id] =" + ID + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        /// <summary>
        ///  传入字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string ID, string CoulmnName)
        {


            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            MyDa.SelectCommand.CommandText = "select " + CoulmnName + " from [CX_NEWS_Class] where  [CX_NEWS_Class_id] =" + ID + "  " + OrderBy;
            #endregion


            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 字段名 返回一个字段的值 调用条数
        /// </summary>
        /// <param name="ID">字段名</param>
        /// <param name="CoulmnName">调用条数</param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_NEWS_Class]     " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        /// 传入字段集合 返回条数据
        /// </summary>
        /// <param name="CoulmnName">字段的数组  数组长度为0 为 得到全部的字段  </param>
        /// <param name="RecordNum">得到记录的条数</param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum)
        {
            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法

            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }

            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_NEWS_Class]    " + OrderBy;

            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }
        /// <summary>
        ///  传入多个字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet Oper_Select(string CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            MyDa.SelectCommand.CommandText = "select Top (" + RecordNum + ")  " + CoulmnName + " from  [CX_NEWS_Class]   where " + Where + "  " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

        /// <summary>
        ///  传入字段集合 返回条数据
        ///  返回 DataSet
        /// </summary>
        /// <param name="CoulmnName">字段名  能在表里找到 字段的数组  数组长度为0 为 得到全部的字段</param>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum, string Where)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            string Cloumn = "";
            for (int i = 0; i < CoulmnName.Length; i++)
            {
                Cloumn += CoulmnName[i].ToString() + ",";
            }

            if (Cloumn != "")
            {
                Cloumn = Cloumn.Substring(0, Cloumn.Length - 1);
            }
            else
            {
                Cloumn = "*";
            }
            MyDa.SelectCommand.CommandText = "select top (" + RecordNum + ") " + Cloumn + " from  [CX_NEWS_Class]   where " + Where + "   " + OrderBy;
            #endregion




            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }


        #region 数据转对象

        /// <summary>
        ///  传入读出数据的条数 条件
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <param name="Where">条件 如 newsid!="" and 0=0 </param>
        /// <returns></returns>
        public Data_CX_NEWS_Class[] Oper_SelectToObject(int RecordNum, string Where)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum, Where));
        }

        /// <summary>
        ///  传入读出数据的条数 
        ///  返回 Data_CX_NEWS 类型的数组
        /// </summary>
        /// <param name="RecordNum">读出条数</param>
        /// <returns></returns>
        public Data_CX_NEWS_Class[] Oper_SelectToObject(int RecordNum)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum));
        }

        #endregion

        #region  用于实现数据转换成类型的方法

        /// <summary>
        /// 把对应表的数据转成对象
        /// </summary>
        /// <param name="MyDs">传入的dataset</param>
        /// <returns></returns>
        private Data_CX_NEWS_Class[] ConvertToObject(DataSet MyDs)
        {

            DataTable Mydt = MyDs.Tables[0];
            //当前的记录数，默认 为 0
            int Count = 0;
            //定义一个方法用于显示数据 类型的集合
            Data_CX_NEWS_Class[] p = new Data_CX_NEWS_Class[1];
            if (Mydt.Rows.Count == 0)
            {
                p = new Data_CX_NEWS_Class[1];
                Count = 1;
            }
            else
            {
                p = new Data_CX_NEWS_Class[Mydt.Rows.Count];
            }

            try
            {
                for (int i = 0; i < Mydt.Rows.Count; i++)
                {
                    Data_CX_NEWS_Class Mydato = new Data_CX_NEWS_Class();
                    #region 实现转换的方法
                    Mydato.CX_NEWS_Class_id = (decimal)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_id].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_id]);
                    Mydato.CX_NEWS_Class_Name = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Name].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Name]);
                    Mydato.CX_Column_id = (decimal)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_Column_id].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? 0 : Mydt.Rows[i][Data_CX_NEWS_Class._CX_Column_id]);
                    Mydato.CX_NEWS_Class_Explier = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Explier].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Explier]);
                    Mydato.CX_NEWS_Class_Itemplitate_Address = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Itemplitate_Address].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Itemplitate_Address]);
                    Mydato.CX_NEWS_Class_Itemplitate_Parame = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Itemplitate_Parame].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Itemplitate_Parame]);
                    Mydato.CX_NEWS_Class_Pic = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Pic].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Pic]);
                    Mydato.CX_NEWS_Class_CreateFielfront = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_CreateFielfront].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_CreateFielfront]);
                    Mydato.CX_NEWS_Class_Directory = (string)(Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Directory].GetType().ToString() == System.DBNull.Value.GetType().ToString() ? "" : Mydt.Rows[i][Data_CX_NEWS_Class._CX_NEWS_Class_Directory]);

                    #endregion
                    p[i] = Mydato;
                }
            }
            catch (Exception ex)
            {
                errorInfo += "执行  把对应表的数据转成对象时出现错误" + ex.Message + ex.Source;
            }
            if (Count != 0)
            {
                p[0] = new Data_CX_NEWS_Class();

            }

            return p;


        }
        #endregion


        /// <summary>
        /// 执行SQL语句 返回dataSet
        /// </summary>
        /// <typeparam name="Tab">数据表</typeparam>
        /// <param name="Sql">执行的SQL</param>
        /// <returns></returns>
        public DataSet ExecuteQuery(string Sql)
        {

            SqlDataAdapter MyDa = new SqlDataAdapter("", TextData.SqlConnStr);
            MyDa.SelectCommand.Connection = TextData.MySql;
            MyDa.SelectCommand.CommandType = CommandType.Text;

            #region CX_NEWS_Class 的查询方法
            MyDa.SelectCommand.CommandText = Sql;
            #endregion



            DataSet MyDs = new DataSet();
            try
            {
                MyDa.Fill(MyDs);
            }
            catch (Exception ex)//資料填充時的異常處理
            {
                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();
                }
                MyDs = null;
                ErrorInfo += "执行查询操作ExecuteQuery(string Sql)时出现错误" + ex.Message;

            }

            if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
            {
                TextData.MySql.Close();

            }
            return MyDs;
        }

    }

    #endregion






























}